package com.qianli.cashmama.trade.mq;

import com.qianli.cashmama.trade.common.mq.MQTagEnum;
import com.qianli.cashmama.trade.common.mq.MQTopicEnum;
import com.qianli.cashmama.trade.common.mq.MessageMQ;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: cashmama-trade-center
 * @description
 * @author: frank
 * @create: 2020-10-13 14:38
 **/
@Service("MQHandlerService")
public class MQHandlerService {

    private static final Logger LOGGER = LoggerFactory.getLogger(MQHandlerService.class);


    @Autowired
    private MessageMQHandler messageMQHandler;

    public void sendMq(String tradeNo, MQTagEnum mqTagEnum, String message) {
        MessageMQ messageMQ = new MessageMQ();
        messageMQ.setMessageId(mqTagEnum.getTag() + "_" + tradeNo + "_" + System.currentTimeMillis());
        messageMQ.setMessage(message);
        messageMQ.setTopic(MQTopicEnum.OPENAPI);
        messageMQ.setTag(mqTagEnum);
        try {
            messageMQHandler.send(messageMQ);
            LOGGER.error("发送mq成功,tradeNo:{},mqTagEnum:{},messageId:{},message:{}", tradeNo, mqTagEnum, messageMQ.getMessageId(), message);
        } catch (Exception e) {
            LOGGER.error("发送mq失败,tradeNo:{},mqTagEnum:{},messageId:{},message:{}", tradeNo, mqTagEnum, messageMQ.getMessageId(), message);
        }
    }
}
